package com.wollo.service.impl;

import com.wollo.domain.Upload;
import com.wollo.mapper.UploadMapper;
import com.wollo.service.UploadService;
import com.wollo.utils.FastDFSUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

/**
 * //
 * //   █████▒█    ██  ▄████▄   ██ ▄█▀       ██████╗ ██╗   ██╗ ██████╗
 * // ▓██   ▒ ██  ▓██▒▒██▀ ▀█   ██▄█▒        ██╔══██╗██║   ██║██╔════╝
 * // ▒████ ░▓██  ▒██░▒▓█    ▄ ▓███▄░        ██████╔╝██║   ██║██║  ███╗
 * // ░▓█▒  ░▓▓█  ░██░▒▓▓▄ ▄██▒▓██ █▄        ██╔══██╗██║   ██║██║   ██║
 * // ░▒█░   ▒▒█████▓ ▒ ▓███▀ ░▒██▒ █▄       ██████╔╝╚██████╔╝╚██████╔╝
 * //  ▒ ░   ░▒▓▒ ▒ ▒ ░ ░▒ ▒  ░▒ ▒▒ ▓▒       ╚═════╝  ╚═════╝  ╚═════╝
 * //  ░     ░░▒░ ░ ░   ░  ▒   ░ ░▒ ▒░
 * //  ░ ░    ░░░ ░ ░ ░        ░ ░░ ░
 * //           ░     ░ ░      ░  ░
 * //                 ░
 *
 * @author Java song
 * @date 2024/9/19 下午7:18
 * @description
 **/
@Service
public class UploadServiceImpl implements UploadService {

    @Autowired
    private UploadMapper uploadMapper;

    @Value("${fastdfs.nginx}")
    private String nginxAddress;
    @Override
    public String uploadService(MultipartFile file, Integer uid) throws Exception {
        String[] strings = FastDFSUtils.uploadFile(file.getInputStream(), file.getOriginalFilename(), "");
        Upload upload = new Upload();
        upload.setUid(uid);
        upload.setGroupName(strings[0]);
        upload.setRemoteName(strings[1]);
        uploadMapper.insertUploadInfoMapper(upload);
        return nginxAddress+"/"+strings[0]+"/"+strings[1];
    }
}
